//引入插件，用于生成打包后的html文件
const htmlWebpackPlugin = require('html-webpack-plugin');
//引入复制文件插件
const CopyWebpackPlugin = require('copy-webpack-plugin');
//引入清除文件插件
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const entryArr = require('./entryArr.js');
let pluginArr = [];
let entry = {};
const pluginConfigFn = function(directory) {
	for(let i of entryArr) {
		pluginArr.push(
			new htmlWebpackPlugin({
				filename: `${i}.html`,
				template: path.resolve(directory, `./src/view/${i}/${i}.html`),
				inject: 'body',
				chunks: [i],
				minify: { //压缩html代码
					//删除空格
					collapseWhitespace: true,
					//删除注释
					removeComments: true
				}
			})
		)
		entry[i] = path.resolve(directory, `./src/js/${i}.js`)
	}

	pluginArr.push(new CopyWebpackPlugin([{
		from: directory + '/src/static/',
		to: directory + '/dist/static'
	}]))
	pluginArr.push(new CleanWebpackPlugin(['dist']));

	return {
		entry: entry,
		plugins: pluginArr
	}
}
module.exports = pluginConfigFn;